/*
 * TextAreaDelegate.h  0.4.0 / Dec 04, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
#ifndef TEXTAREADELEGATE_H
#define TEXTAREADELEGATE_H

#include "Cute4jSwing.h"

#include "QTextArea.h"
#include "TextComponentDelegate.h"

// TextAreaDelegate Class. -----------------------------------------------------

/*!
 * \brief TextArea Delegate.
 *
 * \author Slobodan Vrkacevic
 * \version 0.4.0
 */
class CUTE4J_EXPORT TextAreaDelegate : public TextComponentDelegate
{
  Q_OBJECT
protected:
  TextAreaDelegate(JNIEnv *env, jobject obj);
public slots: // native calls
  void setWrapText(JNIEnv *env, jboolean textWrap);
  void paintComponentView(JNIEnv *env, jlong graphicsPointer);
public: // native calls
  static void initialize(JNIEnv *env, jclass cls);
  static jlong newInstance(JNIEnv *env, jobject obj);
public: // native callbacks
  void paintView(jlong graphicsPointer, jint x, jint y, jint width,
                 jint height);
public:
  inline QTextArea *qTextArea() const;
public:
  virtual void setDocument(JNIEnv *env, jobject document);
  virtual void setEditable(JNIEnv *env, jboolean editable);
  virtual void insertText(JNIEnv *env, jstring text);
  virtual void cut(JNIEnv *env);
  virtual void copy(JNIEnv *env);
  virtual void paste(JNIEnv *env);
  virtual void clear(JNIEnv *env);
  virtual void selectAll(JNIEnv *env);
  virtual jobject getBackground(JNIEnv *env, jclass colorClass);
  virtual void setBackground(JNIEnv *env, jint argb);
  virtual void setNullBackground(JNIEnv *env);
  virtual jint getCursor(JNIEnv *env);
  virtual void setCursor(JNIEnv *env, jint type);
protected:
  virtual void filterEnabledEvents();
private:
  static jmethodID sm_paintViewMID;
};

// TextAreaDelegate :: Inline Member Function. ---------------------------------

/*!
 * \brief Returns QTextArea adaptee.
 *
 * \return QTextArea adaptee
 */
inline QTextArea *TextAreaDelegate::qTextArea() const
{
  return static_cast<QTextArea *>(qObject());
}

// Macro Definitions. ----------------------------------------------------------

#define TEXT_AREA_DELEGATE (reinterpret_cast<TextAreaDelegate *>(delegate))

#endif // TEXTAREADELEGATE_H
